
#include "nane/CodecSystem/Image/ImageCodecSystem.h"
#include "nane/CodecSystem/Image/ImageCodecSystemImpl_.h"
#include "nane/CodecSystem/Image/ImageDecoderImpl_.h"
#include "nane/core/IFileSystem.h"

#include "nane/core/assert.h"

namespace nane 
{
    ////////////////////////////////////////////////////////////////////////////////////////////////
    ImageCodecSystem::ImageCodecSystem()
        : SubSystem<IImageCodecSystem>( new Implementation() )
        , m( static_cast<Implementation*>(SubSystem<IImageCodecSystem>::m) )
    {
        
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    ImageCodecSystem::~ImageCodecSystem()
    {
        Shutdown();
        delete m;
        m = NULL;
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    const char* ImageCodecSystem::GetFileType()
    {
        NANE_ASSERT_RV( m->interface != NULL, "ImageCodecSystem must be initialized", "" );
        return m->interface->GetFileType();
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    ImageDecoder ImageCodecSystem::CreateDecoder( const InputPtr& _input )
    {
        NANE_ASSERT_RV( m->interface != NULL, "ImageCodecSystem must be initialized", NullPtr );
        NANE_ASSERT_RV( _input != NullPtr, "IFile must be valid", NullPtr );

        ImageDecoder::Implementation* imageDecoderImpl = NULL;
        IImageDecoder* imageDecoderInterface = m->interface->CreateDecoder(_input.Get());
        if( imageDecoderInterface != NULL )
        {
            imageDecoderImpl = new ImageDecoder::Implementation(m, imageDecoderInterface);
        }
        return ImageDecoder(imageDecoderImpl);
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    //ImageDecoder* ImageCodecSystem::createDecoder( const char* _filename )
    //{
        
    //}
    ////////////////////////////////////////////////////////////////////////////////////////////////
}   // namespace nane
